﻿using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Separation.WebApi.PolicyRequirement
{
    /// <summary>
    /// 自定义策略授权
    /// </summary>
    //public class MustroleAdminHandler:IAuthorizationHandler
    //{
    //    public Task HandleAsync(AuthorizationHandlerContext context)
    //    {
    //        var Requirements = context.Requirements;

    //        context.Succeed(Requirements.FirstOrDefault());
    //        //context.Fail();
    //        return Task.CompletedTask;
    //    }
    //}

    public class MustroleAdminHandler : AuthorizationHandler<AdminRequirement>
    {
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AdminRequirement requirement)
        {
            //var Requirements = context.Requirements;
            context.Succeed(requirement);
            //context.Fail();
            return Task.CompletedTask;
        }
    }
}
